<?php
class My_SiteMap
    extends DOMDocument
{

    const FREQUENCY_ALWAYS = 'always';
	const FREQUENCY_HOURLY = 'hourly';
	const FREQUENCY_DAILY = 'daily';
	const FREQUENCY_WEEKLY = 'weekly';
	const FREQUENCY_MONTHLY = 'monthly';
	const FREQUENCY_YEARLY = 'yearly';
	const FREQUENCY_NEVER = 'never';
    
	protected $_root;
	
    public function __construct( $version = '1.0', $encoding = 'UTF-8')
    {
        parent::__construct( $version, $encoding);
        
        $this->_root = $this->createElementNS('http://www.sitemaps.org/schemas/sitemap/0.9', 'urlset');
		$this->appendChild( $this->_root );
        
    }
    public function addItem( $loc, $lastmod, $changefreq, $priority )
    {
        $url = $this->createElement('url');
				
        $url->appendChild(
            $this->createElement('loc', $loc)
        );
        
        $url->appendChild(
            $this->createElement('lastmod', $lastmod)
        );
        
        $url->appendChild(
            $this->createElement('changefreq', $changefreq)
        );
        
        $url->appendChild(
            $this->createElement('priority', number_format($priority, 2))
        );
        
        $this->_root->appendChild( $url );
        
    }
}